package com.uidp.domain;

import static com.uidp.bundle.Messages.GROUP_NAME_NOT_FOUND;

import java.util.ArrayList;
import java.util.List;

import com.acsior.dac.exeption.DataAccessException;
import com.acsior.sbc.exception.BusinessException;
import com.acsior.sbc.exception.SearchException;
import com.acsior.sbc.exception.ValidationException;
import com.acsior.sbc.impl.hibernate.HibernateBusinessObject;
import com.uidp.hibernatelayer.ModulModulElementsDAO;
import com.uidp.hibernatelayer.ModulModulElementsVO;
import com.uidp.search.ModulModulElemntSearch;

public class ModulModulElements extends
		HibernateBusinessObject<ModulModulElementsVO, ModulModulElementsDAO> {
	private Modul modul;
	private ModulElements modulElements;

	/**
	 * 
	 * @param username
	 *            - потребителско име
	 * @return IUser - резултат
	 * 
	 * @throws BusinessException
	 * @throws SearchException
	 */
	public static List<ModulModulElements> searchModulElements(Modul modul)
			throws BusinessException, SearchException {
		List<ModulModulElements> searchModulElements = new ArrayList<ModulModulElements>();
		ModulModulElemntSearch search = new ModulModulElemntSearch();
		search.setModul(modul);
		search.execute();

		if (search.getResult().isEmpty()) {
			throw new BusinessException(GROUP_NAME_NOT_FOUND,
					modul.getModulname());
		}
		searchModulElements = search.getResult();
		return searchModulElements;
	}

	public ModulModulElements() throws BusinessException {
		super();
	}

	public ModulModulElements(ModulModulElementsVO h) throws BusinessException {
		super(h);
	}

	/** @see PersistentObject#initialize() */
	@Override
	protected void initialize() throws BusinessException {
		super.initialize();
		setModul(new Modul());
		setModulElements(new ModulElements());
	}

	@Override
	protected void setValues(ModulModulElementsVO h) throws DataAccessException {
		h.setModul(getModul().findData());
		h.setModulElements(getModulElements().findData());

	}

	@Override
	protected void copyProperties(ModulModulElementsVO d, boolean deepCopy)
			throws BusinessException {
		setModul(new Modul(d.getModul()));
		setModulElements(new ModulElements(d.getModulElements()));

	}

	@Override
	protected void validate() throws ValidationException {
		// TODO Auto-generated method stub

	}

	@Override
	protected Class<ModulModulElementsDAO> getDAOClass() {
		return ModulModulElementsDAO.class;
	}

	public Modul getModul() {
		return modul;
	}

	public void setModul(Modul modul) {
		this.modul = modul;
	}

	public ModulElements getModulElements() {
		return modulElements;
	}

	public void setModulElements(ModulElements modulElements) {
		this.modulElements = modulElements;
	}

}
